<extend name="Base/common"/>
<block name="body">
<!--收货地址-->
    <link href="__CSS__/top.css" rel="stylesheet">
    <link href="__CSS__/common.css" rel="stylesheet">
    <div class="bd">
    <div class="center_right" id="MemberCenterCtrl" style="display: block;">

        <div class="red" style="clear:both; overflow:hidden; padding:10px;">收货地址管理（选中表示为默认）</div>



        <form method="post" class="person-add" name="form" action="{:U('center/update')}">


            <ul style="margin-left:40px;" class="list">
                <volist name="list" id="vo">


                    <li><span><php>$s=$vo['status'];if($s==1){
                        echo '<input type="radio" checked="checked" name="id" value="'.$vo['id'].'">';
                        }
                        if($s==0){
                        echo '<input type="radio"  name="id" value="'.$vo['id'].'">';
                        }
                    </php>


		  </span>{$vo.address} {$vo.realname}  {$vo.cellphone}</li>

                </volist>
                <li class="add" style="display:none"><span></span>联系地址<input type="text"  id="address"  name="address">联系人：<input type="text" id="realname" >联系方式<input type="text" id="phone"  ><input type="button" class=" rosy" id="btn-save" value="保存" /></li>
                <li><input type="button" class="btn-xiugai redd"  value="设置默认" onclick="shezhi();"/>&nbsp;<input type="button" class="btn-xiugai blue"  value="删除" onclick="shanchu();"/>&nbsp;<input type="button" class="btn-xiugai orange" id="btn-add" value="增加" />  </li><BR></ul>
        </form>




        <script type="text/javascript">

            $("#btn-add").click(function(){ $("li.add").toggle(); });

            //增加地址
            $("#btn-save").click(function(){
                var p=$("#address").val();
                var real=$("#realname").val();
                var ph=$("#phone").val();
                var url="{:U('center/save')}";
                if(p==''||real==''||ph==''){alert("内容不能为空");return false;}
                else{$.ajax({
                    type:'post', //传送的方式,get/post
                    url:url, //发送数据的地址
                    data:{posi:p,pho:ph,rel:real},
                    dataType: "json",
                    success:function(data)
                    {var str='<li><span><input type="radio" name="id" value="'+data+'" id="default"/></span>'+
                            p+"&nbsp;"+real+"&nbsp;"+ph+'</li>';
                        $("li.add").before(str);$("li.add").fadeOut();
                    },
                    error:function (event, XMLHttpRequest, ajaxOptions, thrownError) {
                        alert(XMLHttpRequest+thrownError); }
                })
//ajax over
                }//else over
            });
            //设置默认
            function shezhi() {

                var val=$('input:radio[name="id"]:checked').val();
                //判断新地址是否选中,获取地址id
                if(val==null){

                    alert("请选择一个地址!");return false;
                }
                else{

                    $.ajax({
                        type:'post', //传送的方式,get/post
                        url:'{:U("center/shezhi")}', //发送数据的地址
                        data:{id:val},
                        dataType: "json",
                        success:function(data)
                        {alert(data);
                        },
                        error:function (event, XMLHttpRequest, ajaxOptions, thrownError) {
                            alert(XMLHttpRequest+thrownError); }
                    })

                    //ajax over

                }

                //else over
            }
            //设置默认
            function shanchu() {

                var val=$('input:radio[name="id"]:checked').val();
                //判断新地址是否选中,获取地址id
                if(val==null){

                    alert("请选择一个地址!");return false;
                }
                else{

                    $.ajax({
                        type:'post', //传送的方式,get/post
                        url:'{:U("center/deleteAddress")}', //发送数据的地址
                        data:{id:val},
                        dataType: "json",
                        success:function(data)
                        {alert(data.msg);window.location.reload();
                        },
                        error:function (event, XMLHttpRequest, ajaxOptions, thrownError) {
                            alert(XMLHttpRequest+thrownError); }
                    })

                    //ajax over

                }

                //else over
            }




        </script>
        <!-- 个人中心 初始状态 end --></div></div>
    <script type="text/javascript">_init_area();</script>

</block>